home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Celestin Apprentice 5
/
Apprentice-Release5.iso
/
Source Code
/
Libraries
/
Dots & Pixels
/
headers
/
flowsettings.h
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-29
|
5KB
|
190 lines
#pragma once
//
// flowsettings: a simple way to read and write flow parameters
//
class flowsettings
{
public:
double translation_x;
double translation_y;
double expansion;
double rotation; // in degrees per second
double shear_magnitude;
double shear_direction; // in degrees
flowsettings();
void init();
int is_translation_free() const;
int is_rotation_free() const;
int is_expansion_free() const;
int is_shear_free() const;
int is_unity() const;
int operator==( const flowsettings &that) const;
friend ostream& operator<<( ostream& destroom,
const flowsettings &thesettings);
friend istream& operator>>( istream& destroom, flowsettings &thesettings);
};
//
// flowexpsettings effectively contains three settings; the first is the
// reference flow, the second and third contain the starting and ending point
// of the 'trajectory' alongside which testing takes place.
// Note that usually, point_zero will equal the reference flow. We allow
// these to differ because we migth wish to ask for instance:
// 'which one rotates faster', where the reference flow is rotating and
// expanding, whereas the test flows are only rotating.
// The 'distance' between 'point_zero' and 'point_one' determines the 'unit'.
//
class flowexpsettings : public flowsettings
{
public:
flowsettings point_zero;
flowsettings point_one;
flowexpsettings();
void getvalue( flowsettings *new_value, const double lambda);
//
// the ..._does_change members return true whenever the relevant
// parts of point_zero and/or point_one differ.
//
int dx_does_change() const;
int dy_does_change() const;
int translation_does_change() const;
int exp_does_change() const;
int rot_does_change() const;
int mag_does_change() const;
int dir_does_change() const;
int shear_does_change() const;
friend ostream& operator<<( ostream& destroom,
const flowexpsettings &thesettings);
friend istream& operator>>( istream& destroom,
flowexpsettings &thesettings);
//
// The advantage of 'shorthand_out' and 'longhand_out' over
// "ostream &operator>>" is that they are better suited for import of the
// data into a spreadsheet.
//
// Use 'shorthand_out' to write the settings in a non-recoverable format
// 'shorthand_out' can be a convenient format for importing into a
// spreadsheet, but the number of columns produced by 'shorthand_out'
// varies with the number of varying parameters in the flowexpsettings.
//
// 'longhand_out' is a similar format, but with a fixed number of columns.
//
// If I knew how to do it, I would possibly implement this with an IOStream
// manipulator.
//
// The flag 'force_three' is used to indicate that 'point_zero' should
// also be output when it is equal to the reference flow.
//
void shorthand_out( ostream &destroom = cout, int force_three = false) const;
void longhand_out( ostream &destroom = cout, int force_three = false) const;
private:
static double lin_interpolate( double start, double end, double lambda);
static double log_interpolate( double start, double end, double lambda);
};
inline void flowsettings::init()
{
translation_x = 0.0;
translation_y = 0.0;
expansion = 1.0;
rotation = 0.0;
shear_magnitude = 1.0;
shear_direction = 0.0;
}
inline flowsettings::flowsettings()
{
init();
}
inline int flowsettings::is_translation_free() const
{
return ((translation_x == 0.0) && (translation_y == 0.0));
}
inline int flowsettings::is_rotation_free() const
{
return (rotation == 0.0);
}
inline int flowsettings::is_expansion_free() const
{
return (expansion == 1.0);
}
inline int flowsettings::is_shear_free() const
{
return (shear_magnitude == 1.0);
}
inline int flowsettings::is_unity() const
{
return ( is_translation_free() &&
is_expansion_free() && is_rotation_free() &&
is_shear_free() && (shear_direction == 0.0)
);
}
inline flowexpsettings::flowexpsettings() : flowsettings()
{
point_zero.init();
point_one.init();
}
inline double flowexpsettings::lin_interpolate(
double start, double end, double lambda)
{
return (1.0 - lambda) * start + lambda * end;
}
inline double flowexpsettings::log_interpolate(
double start, double end, double lambda)
{
return exp( (1.0 - lambda) * log( start) + lambda * log( end));
}
inline int flowexpsettings::dx_does_change() const
{
return ((translation_x != point_one.translation_x)
|| (translation_x != point_zero.translation_x));
}
inline int flowexpsettings::dy_does_change() const
{
return ((translation_y != point_one.translation_y)
|| (translation_y != point_zero.translation_y));
}
inline int flowexpsettings::exp_does_change() const
{
return ((expansion != point_one.expansion)
|| (expansion != point_zero.expansion));
}
inline int flowexpsettings::rot_does_change() const
{
return ((rotation != point_one.rotation)
|| (rotation != point_zero.rotation));
}
inline int flowexpsettings::mag_does_change() const
{
return ((shear_magnitude != point_one.shear_magnitude)
|| (shear_magnitude != point_zero.shear_magnitude));
}
inline int flowexpsettings::dir_does_change() const
{
return ((shear_direction != point_one.shear_direction)
|| (shear_direction != point_zero.shear_direction));
}